package com.wyc.controller;

import com.wyc.pojo.Emp;
import com.wyc.pojo.Result;
import com.wyc.service.EmpsService;
import com.wyc.utils.JWTUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {
    @Autowired
    private EmpsService empsService;
    @Autowired
    private JWTUtils jwtUtils;

    //登录
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        Emp login = empsService.login(emp);
        if(login!=null){
            //生成jwt
            String jwt = jwtUtils.build(login.getId() + "");
            return Result.success(jwt);
        }
        return Result.error();
    }
}
